
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../http/api.dart';
import '../../main.dart';

class PersonModel{

  RxBool isEmpty = RxBool(false);

  _checkFace() {
    faceQuery(currentTask.uid).then((value){
      isEmpty.value = value;
    });
  }

  show({showFaceAuth = false,callback}){
    if(showFaceAuth){
      _checkFace();
    }
    return Container(
        height: 310.h,
        width: 180.w,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(4.r)),
        ),
        child:  Column(
          children: [
            SizedBox(height: 30.h,),
            Image.asset("assets/images/head.jpg",width: 60.w,fit: BoxFit.fitWidth,),
            Text("${currentTask.uName}",style: TextStyle(color: Colors.blue,fontSize: 14.sp),),
            SizedBox(height: 3.h,),
            Text("读者证号:${currentTask.uid}",style: TextStyle(color: Colors.blue,fontSize: 10.sp),),
            SizedBox(height: 3.h,),

            if(showFaceAuth)...[
              InkWell(
                  onTap: (){
                    callback();
                  },
                  child: Obx(() => isEmpty.value?
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text("人脸登陆:已注册  ",style: TextStyle(color: Colors.blue,fontSize: 10.sp),),
                      Image.asset("assets/images/camera_change.png",width: 34.w,fit: BoxFit.fitWidth,),
                    ],
                  ):
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text("人脸登陆:未注册  ",style: TextStyle(color: Colors.blue,fontSize: 10.sp),),
                      Image.asset("assets/images/camera_change.png",width: 34.w,fit: BoxFit.fitWidth,),
                    ],
                  ),
                  )
              ),
            ],
            SizedBox(height: 80.h,),
            Stack(
              children: [
                Container(
                  width: 140.w,
                  height: 20.h,
                  decoration: BoxDecoration(
                    color: Colors.grey[400],
                    borderRadius: BorderRadius.all(Radius.circular(2.r)),
                  ),
                ),
                Container(
                  width: ((currentTask.readerEntity!.currentBorrowCount!/currentTask.readerEntity!.limitCount!)*140).w,
                  height: 20.h,
                  decoration: BoxDecoration(
                    color: Colors.green,
                    borderRadius: BorderRadius.all(Radius.circular(2.r)),
                  ),
                ),
              ],
            ),
            SizedBox(height: 3.h,),
            Row(
              children: [
                SizedBox(width: 20.w,),
                Container(
                  width: 10.w,
                  height: 10.h,
                  decoration: BoxDecoration(
                    color: Colors.green,
                    borderRadius: BorderRadius.all(Radius.circular(2.r)),
                  ),
                ),
                Text(" 已借数量:${currentTask.readerEntity!.currentBorrowCount}",style: TextStyle(color: Colors.black,fontSize: 10.sp),),
              ],
            ),
            SizedBox(height: 3.h,),
            Row(
              children: [
                SizedBox(width: 20.w,),
                Container(
                  width: 10.w,
                  height: 10.h,
                  decoration: BoxDecoration(
                    color: Colors.grey[400],
                    borderRadius: BorderRadius.all(Radius.circular(2.r)),
                  ),
                ),
                Text(" 可借数量:${currentTask.readerEntity!.limitCount}",style: TextStyle(color: Colors.black,fontSize: 10.sp),),
              ],
            ),
          ],
        )
    );
  }

}

